package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import util.DBUtil;
import bean.Alarm;
import bean.Detection;

public class baojingdeo {
	
	public ArrayList<Alarm> getAlarmList(String sql) throws SQLException {
		Connection conn = DBUtil.open();
		Statement stmt = conn.createStatement();
		ResultSet rs = null;
		ArrayList<Alarm> list = new ArrayList<Alarm>();

		NumberFormat precent = NumberFormat.getPercentInstance();
		precent.setMinimumFractionDigits(0);
		// ��д�ٷ���

		try {
			 rs = stmt.executeQuery(sql);
			while (rs.next()) {
				SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
				
				String outlet_name=rs.getString(1);
				String company_name=rs.getString(2);
				String oreport_num=rs.getString(3);
				String oreport_date=rs.getString(4);
				String freport_num=rs.getString(5);
				String freport_date=rs.getString(6);
				
				Alarm al=new Alarm();
				
				String data1=time.format(time.parse(oreport_date));
				String data2=time.format(time.parse(freport_date));
				
				al.setCompany_name(company_name);
				al.setOutlet_name(outlet_name);
				al.setOreport_num(oreport_num);
				al.setOreport_date(data1);
				al.setFreport_num(freport_num);
				al.setFreport_date(data2);
				
				list.add(al);
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}finally {
			DBUtil.close();
	    }
		return list;
	}
}
